import os
import pandas as pd
from flask import Flask, render_template
from web_operation import catch_save

app = Flask(__name__)
app.secret_key = os.urandom(24)


@app.route('/')
def index():
    return render_template('home.html')


@app.route('/button1')
def button1():
    catch_save.parse()
    return '爬取成功'


@app.route('/button2')
def button2():
    catch_save.create_insert_table()
    return '保存成功'


@app.route('/demo2/')
def column2():
    return render_template('demo2.html')


@app.route('/demo3/')
def column3():
    filename = '蔚蓝图书.csv'
    data = pd.read_csv(filename, header=None)
    return render_template('demo3.html', data=data)


@app.route('/demo4/')
def column4():
    return render_template('demo4.html')


if __name__ == '__main__':
    app.run(host="0.0.0.0", debug=True)
